<template>
  <div class="l-rblock">
    <l-data-list
      isApp
      :columns="columns"
      :isMore="!!data.moduleId"
      :label="data.label"
      :data="dataSource"
    ></l-data-list>
  </div>
</template>
<script>
const apiScheme = window.$api.custmerForm.scheme;
export default {
  props: ["data", "isPreview"],
  data() {
    return {};
  },
  asyncComputed: {
    dataSource: {
      async get() {
        const { f_Scheme, f_Id } = (await this.$awaitWraper(apiScheme.getHistory(this.data.formVerison))) || {};
        this.formScheme = JSON.parse(f_Scheme);
        this.formSchemeId = f_Id;

        if (this.data.orderId && this.data.formVerison) {
          if (this.formScheme.formType == 2) {
            const apiGet = this.formScheme.db.find((item) => item.apiType == 0);
            const api = await this.$awaitWraper(apiScheme.apiParams(`${this.apiUrl}data/datainterface/${apiGet.f_Id}`));
            let params = {
              rows: this.data.limitRow == 1 ? this.data.maxRows : 100000,
              page: 1,
              sidx: this.data.orderId,
            };
            const data = (await this.$awaitWraper(apiScheme.apiParams(api.f_Url, api.f_RequestMethod, params))) || {};
            return data.rows || [];
          } else {
            const queryData = {
              paginationInputDto: {
                rows: this.data.limitRow == 1 ? this.data.maxRows : 100000,
                page: 1,
                sidx: this.data.orderId,
              },
            };
            const data =
              (await this.$awaitWraper(apiScheme.getDataPage(this.data.moduleId, this.data.formVerison, queryData))) ||
              {};
            return data.rows || [];
          }
        } else {
          return [];
        }
      },
    },
  },
  computed: {
    columns() {
      const titleCol = this.data.titleOpt || {};
      titleCol.prop = this.data.titleKey;
      titleCol.width = 70;
      titleCol.align = "left";

      const subTitleCol = this.data.subTitleOpt || {};
      subTitleCol.prop = this.data.subTitleKey;
      subTitleCol.width = 30;
      subTitleCol.align = "right";

      return [titleCol, subTitleCol];
    },
  },
  methods: {},
};
</script>
